//=====================================================================
// OdbgExt DBGSQL.CPP
//		Created by : Jeffda
//      Created on : 4/25/2008
//   Last Modified : 
//  This code adds SQL Ability to the debugger extention
//=====================================================================


#include <sql.h>
#include <sqlext.h>



typedef struct STR_BINDING {
	SQLSMALLINT	siDisplaySize;			/* size to display  */
	TCHAR		*szBuffer;				/* display buffer   */
	SQLINTEGER	indPtr;					/* size or null     */	
	BOOL		fChar;					/* character col?   */
	struct STR_BINDING	*sNext;	/* linked list		*/
} BINDING;




#define	TRYODBC(h,ht,x) {RETCODE	iRet=x;\
								if (iRet != SQL_SUCCESS) \
								{ \
									HandleError(h,ht,iRet); \
								} \
								if (iRet == SQL_ERROR) \
								{ \
									dprintf("Error in " #x "\n"); \
									goto Exit;	\
								}  \
							}
							
#define	TRYCONNECTODBC(h,ht,x) {RETCODE	iRet=x;\
								if (iRet != SQL_SUCCESS) \
								{ \
									HandleError(h,ht,iRet); \
									bConnected = FALSE; \
								} \
								else \
								{ \
								   bConnected = TRUE; \
								} \
								if (iRet == SQL_ERROR) \
								{ \
									dprintf("Error in " #x "\n"); \
									goto Exit;	\
								}  \
							}
							


int dbgExecSQL(char * szInput, int showresults);


/******************************************/
/* Structure to store information about   */
/* a column.
/******************************************/




/******************************************/
/* Forward references                     */
/******************************************/

void HandleError(SQLHANDLE	hHandle,	
				SQLSMALLINT	hType,	
			    RETCODE	RetCode);
		
void DisplayResults(HSTMT		lpStmt,
			   SQLSMALLINT	cCols);

void AllocateBindings(HSTMT	lpStmt,
					  SQLSMALLINT	cCols,
					  BINDING		**lppBinding,
					  SQLSMALLINT	*lpDisplay);


void DisplayTitles(HSTMT		lpStmt,
					  DWORD		siDisplaySize,
					  BINDING	*pBinding);
	
void SetConsole(	DWORD      		siDisplaySize,
					BOOL			fInvert);

/*****************************************/
/* Some constants                        */
/*****************************************/


#define	DISPLAY_MAX	50			// Arbitrary limit on column width to display
#define	DISPLAY_FORMAT_EXTRA 3	// Per column extra display bytes (| <data> )
#define	DISPLAY_FORMAT		"%c %*.*s "
#define	DISPLAY_FORMAT_C	"%c %-*.*s "
#define	NULL_SIZE			6	// <NULL>

#ifdef UNICODE
#define	PIPE				TEXT('|')
#else
#define PIPE				179 // |
#endif
